package com.wiscamp.ninechapters.problems.infrastructure.po.sheets;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.wiscamp.ninechapters.ddd.PersistenceObject;
import jakarta.persistence.*;
import lombok.Data;

import java.io.Serial;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;

/**
 * 答题卡
 */
@Table(name = "sheets")
@Entity
@Data
public class SheetPO implements PersistenceObject {
    @Serial
    private static final long serialVersionUID = -1848691205502465264L;

    /**
     * 答题卡编号
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "sheet_id", insertable = false, nullable = false)
    private long sheetId = 0;

    /**
     * 答题卡类型
     */
    @Column(name = "sheet_type_id", nullable = false)
    private int sheetTypeId = 0;

    /**
     * 用户编号
     */
    @Column(name = "user_id", nullable = false)
    private long userId = 0;

    /**
     * 开始时间
     */
    @Column(name = "begin_time", nullable = false)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime beginTime;

    /**
     * 结束时间
     */
    @Column(name = "end_time")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime endTime;

    /**
     * 习题集编号
     */
    @Column(name = "set_id", nullable = false)
    private long setId = 0;

    /**
     * 分数
     */
    @Column(name = "gain_score", nullable = false)
    private double gainScore = 0;

    /**
     * 答题卡状态
     */
    @Column(name = "sheet_status_id", nullable = false)
    private int sheetStatusId = 0;

    /**
     * 任务编号
     */
    @Column(name = "task_id", nullable = false)
    private long taskId = 0;

    /**
     * 答题卡明细列表
     */
    // @JoinColumn(name = "sheet_id", nullable = false, insertable = false, updatable = false)
    // @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @Transient
    private Collection<SheetDetailPO> details = new ArrayList<>();
}